<template>
  <div class="page-department">
    <div class="component-mainHeader">
      <div class="top">
        <div class="topleft">
          <p>
            <span class="iconfont" style="color:#1abc9a;margin-right:3px;">&#xe607;</span>成员管理
          </p>
        </div>
        <div class="topright">
          <el-button type="info" @click="$router.go(0)">
            <span style="font-weight:700;margin-right:5px;" class="iconfont">&#xe662;</span>刷新
          </el-button>
        </div>
      </div>
    </div>
    <div class="component-searchHeader">
      <div class="search-header">
        <div class="left-title">
          <p class="left-text">
            <span class="iconfont" style="font-weight:700;margin-right:3px;">&#xe63d;</span>筛选查询
          </p>
          <div class="right">
            <button @click="searchInfo">查询</button>
          </div>
        </div>
      </div>
    </div>
    <div class="component-search-box">
      <el-form :inline="true" :model="formInline" class="demo-form-inline" @submit.native.prevent>
        <el-form-item label="输入搜索：">
          <el-input clearable v-model="formInline.search" placeholder="用户名/姓名/所属角色" @keyup.enter.native="dataInit"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <div class="component-listHeader">
      <div class="search-header">
        <div class="left-title">
          <p class="left-text">
            <span class="iconfont">&#xe61e;</span>
            成员列表
          </p>
          <div class="right">
            <button  @click="add">添加</button>
          </div>
        </div>
      </div>
    </div>

    <div class="table">
      <el-table ref="multipleTable" :data="info" tooltip-effect="dark" style border >
        <el-table-column label="成员账号" align="center" width="138" prop="userName"></el-table-column>
        <el-table-column label="姓名" align="center" width="138" prop="userTruename"></el-table-column>
        <el-table-column label="所属部门" align="center" width="138" prop="orgName"></el-table-column>
        <el-table-column label="所属角色" align="center" prop="roleNames"></el-table-column>
        <el-table-column label="添加时间" align="center" width="158">
          <template slot-scope="scope">{{scope.row.createDate | dateFilter}}</template>
        </el-table-column>
        <el-table-column label="最后登录" align="center" width="158">
          <template slot-scope="scope">{{scope.row.lastLoginDate | dateFilter}}</template>
        </el-table-column>
        <el-table-column label="是否启用" align="center" width="92">
          <template slot-scope="scope">
            <el-switch v-model="scope.row.userStatus" :disabled="true" active-color="#1abc9a" inactive-color="#e4e4e4"></el-switch>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <a @click.prevent="edit(scope.row)">编辑</a>
            <a @click.prevent="deleteInfo(scope.row.userId)">删除</a>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <div class="component-paging" v-if="info.length>1">
      <div class="table-bottom">
        <div class="bottom-left">
        </div>
        <div class="paging">
          <div class="paging-left">
            <p>
              共
              <span>{{Math.ceil(total/pageSize)}}</span> 页/
              <span>{{total}}</span> 条数据
            </p>
          </div>
          <el-pagination
            background
            @size-change="SizeChange($event,dataInit,currentPage,pageSize)"
            @current-change="CurrentChange($event,dataInit,currentPage,pageSize)"
            :current-page="currentPage"
            :page-sizes="[10, 20, 30]"
            :page-size="pageSize"
            layout="sizes, prev, pager, next, jumper"
            :total="total"
          ></el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "member",
  data() {
    return {
      info: [],
      formInline: {
        search: "",
        select: ""
      },
      limit: true,
      // 数据总条数
      total: 0,
      // 每页显示数据的条数
      pageSize: 10,
      // 当前显示的页面页码
      currentPage: 1,
    };
  },
  created() {
    this.dataInit(this.currentPage, this.pageSize);
  },
  mounted() {},
  methods: {
    //获取数据列表、根据用户和部门查询
    dataInit(currentPage, pageSize, search) {
      var that = this;
      let suCb = function(res) {
        if (res.data.flag === 1) {
          res.data.data.map(item => {
            item.roleNames = item.roleList.map(item=>{return item.roleName}).join(',');
            item.roleIds = item.roleList.map(item=>{return item.roleId}).join(',');
            item.userStatus = item.userStatus==1?true:false;
          })
          that.info = res.data.data;
          that.total = res.data.rowCount;
          console.log(that.info,res)
        };
      };
      let erCb = function(res) {
        console.log(res);
      };
      let postData = {
        pageCurrent: that.currentPage,
        pageSize: that.pageSize,
        info: that.formInline.search
      };
      let palyParam = {
        url: "/api/web/sysUser/selectUser",
        methods: "post",
        data: postData,
        success: suCb,
        error: erCb
      };
      that.$https(palyParam);
    },
    searchInfo(){
      this.currentPage = 1;
      this.dataInit();
    },
    add() {
      this.$router.push({
        name: "editMember"
      });
    },
    edit(row) {
      console.log(row)
//      return false;
      this.$router.push({
        name: "editMember",
        params: {editInfo : row}
      });
    },
    deleteInfo(id) {
      this.$confirm("确认删除吗？")
        .then(_ => {
          let that = this,
        suCb = res => {
          console.log(res);
          that.$msg('删除成功！')
          that.searchInfo()
        };
      let erCb = res => {
          console.log(res);
        };
      let params = {
        url: "/api/web/sysUser/deleteUser",
        methods: "post",
        data: {userId:id},
        success: suCb,
        error: erCb
      };
      that.$https(params);
        })
        .catch(_ => {});
    }
  },
};
</script>

<style scoped>
.component-mainHeader .top .topright {
  font-size: 24px;
}

.component-searchHeader .search-header {
  width: 1100px;
  box-sizing: border-box;
  border: 1px solid rgba(228, 228, 228, 1);
  background-color: rgba(255, 255, 255, 1);
  margin: 20px auto 0;
}

.component-searchHeader .search-header .left-title {
  display: flex;
  justify-content: space-between;
  width: 100%;
  background-color: rgba(243, 243, 243, 1);
  height: 45px;
  box-sizing: border-box;
}

.component-searchHeader .search-header .left-title .left-text {
  width: 20%;
  color: #666;
  font-family: "微软雅黑";
  font-weight: 400;
  font-size: 12px;
  line-height: 45px;
  text-align: left;
  margin: 0 0 0 30px;
}

.component-searchHeader .right {
  width: 70%;
  display: flex;
  justify-content: flex-end;
  margin-right: 30px;
}

.component-searchHeader .right button {
  padding: 0 15px;
  height: 30px;
  margin: 6px 5px;
  line-height: 30px;
  font-size: 12px;
  color: #666;
  background-color: #fff;
  border: 1px solid #ccc;
}

.component-searchHeader .right button:hover {
  background-color: #f3f3f3;
}

.component-search-box {
  width: 1100px;
  height: 60px;
  box-sizing: border-box;
  background-color: #fff;
  border: 1px solid #e4e4e4;
  border-top: none;
  margin: 0 auto;
  text-align: left;
  padding-left: 30px;
  line-height: 60px;
}

.component-search-box .el-input__inner {
  height: 35px;
  display: inline-block;
}

.component-listHeader .search-header {
  width: 1100px;
  box-sizing: border-box;
  border: 1px solid rgba(228, 228, 228, 1);
  background-color: rgba(255, 255, 255, 1);
  margin: 20px auto 0;
  border-bottom: 0;
}

.component-listHeader .search-header .left-title {
  display: flex;
  justify-content: space-between;
  width: 100%;
  background-color: rgba(243, 243, 243, 1);
  height: 45px;
  box-sizing: border-box;
}

.component-listHeader .search-header .left-title .left-text {
  width: 20%;
  color: #666;
  font-family: "微软雅黑";
  font-weight: 400;
  font-size: 12px;
  line-height: 45px;
  text-align: left;
  margin: 0 0 0 30px;
}

.component-listHeader .search-header .right {
  width: 70%;
  display: flex;
  justify-content: flex-end;
  margin-right: 10px;
}

.component-listHeader .search-header .right button {
  padding: 0 15px;
  height: 30px;
  width: 80px;
  margin: 6px 5px;
  line-height: 30px;
  font-size: 14px;
  color: #666;
  background-color: #fff;
  border: 1px solid #ccc;
}

.component-listHeader .search-header .right button:hover {
  background-color: #f3f3f3;
}

.component-listHeader .search-header .right .right-select-margin {
  margin-top: 6px;
  margin-right: 8px;
}

.table {
  width: 1100px;
  margin: 0 auto;
}

/* 下面都是修改饿了么ui的下拉框和按钮选中后的样式 */

.el-select .el-input.is-focus .el-input__inner,
.el-select .el-input__inner:focus {
  border-color: #e4e4e4;
}

.el-select-dropdown__item.selected {
  color: #666;
  font-weight: 400;
}

.el-select-dropdown {
  min-width: 100px !important;
  top: 50px !important;
  margin-left: 5px;
}
.el-select-dropdown__item {
  height: 26px;
  line-height: 26px;
}

.el-select .el-input__inner {
  width: 100px;
  padding: 0 8px;
  height: 30px;
  margin: 6px 5px;
}

.el-table .cell a {
  color: #1abc9a;
  text-decoration: none;
  cursor: pointer;
  margin-left: 5px;
}
</style>
